package cn.xinfei.xdecision.common.model.component.guiderule.vo;

import cn.xinfei.xdecision.common.model.BaseDO;
import cn.xinfei.xdecision.common.model.component.scriptrule.RuleScriptVersion;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors
@ToString(callSuper = true)
public class RuleInfoVo extends BaseDO implements Serializable {
    private static final long serialVersionUID = -13354133324148507L;
    @TableId(type = IdType.AUTO)
    private Long id;//主键

    private String name;//规则名称

    private String code;//规则代码

    private String description;//规则描述

    private Long folderId;//文件夹id

//    private Long updateUserId;//修改人id

    private Long organId;//组织id

    private Integer status;//状态    0:新建,1:启用,2:停用


    private Integer difficulty;//规则难度：1:简单规则,2:复杂规则,3:脚本规则

    private String scriptType;//脚本类型python，js，groovy


    @TableField(exist = false)
    private List<Long> folderIds;

    @TableField(exist = false)
    private Long versionId;//执行版本的id

    @TableField(exist = false)
    private RuleScriptVersion scriptVersion;

    @TableField(exist = false)
    private List<RuleScriptVersion> ruleScriptVersionList;




    @TableField(exist = false)
    private RuleVersionVo version;

    @TableField(exist = false)
    private List<RuleVersionVo> ruleVersionList;

    /**
     * 拒绝分支码id
     * 冗余
     */
    @TableField(exist = false)
    private Long rejectBranchCodeId;


    public void setRuleScriptVersionList(List<RuleScriptVersion> ruleScriptVersionList) {
        this.ruleScriptVersionList = ruleScriptVersionList;
        List<RuleVersionVo> ruleVersionList = new ArrayList<>();
        if (ruleScriptVersionList != null && !ruleScriptVersionList.isEmpty()) {
            for (RuleScriptVersion ruleScriptVersion : ruleScriptVersionList) {
                RuleVersionVo ruleVersionVo = new RuleVersionVo();
                BeanUtils.copyProperties(ruleScriptVersion, ruleVersionVo);
                ruleVersionList.add(ruleVersionVo);
            }
        }
        this.ruleVersionList = ruleVersionList;
    }
}
